<template>
<!-- 点位搜索组件 -->
  <div class="seareh_box">
    <el-input
      v-model.trim="searchName"
      size="small"
      prefix-icon="el-icon-search"
      placeholder="请输入点位名称"
      clearable
    ></el-input>
    <ul class="dataList">
      <li v-for="item in pointsSearch(searchName)" :key="item.pointName" @click="getHomeId(item.pointName)">{{item.pointName}}</li>
      <div class="no-search center marginT-6" v-if="!arrLength">
        <!-- <img src="@/assets/images/home/no-search.svg" alt /> -->
        <div class="cr-white marginT-6 fs-14">没有找到该点位</div>
      </div>
    </ul>
  </div>
</template>

<script>
export default {
  name: "searchList",
  props:{
    dataList:{
      type:Array,
      default:()=>[]
    }
  },
  data(){
    return {
      searchName:""
    }
  },
  methods:{
    /* 关键词搜索 */
    pointsSearch(name) {
      if (!name) {
        this.arrLength = true;
        return;
      }
      const newList = [];
      this.dataList.forEach((item, i) => {
        if (item.pointName.indexOf(name) !== -1) {
          newList.push(item);
        }
      });
      this.arrLength = newList.length;
      return newList;
    },
    /* 首页企业列表id */
    getHomeId(name) {
      this.$emit("homeMap", name);
      this.searchName = "";
    },
  }
};
</script>

<style lang="scss" scoped>
.seareh_box {
  position: absolute;
  top: 11.5%;
  left: 22.5%;
  z-index: 2;
  transition: all 0.3s;
  .dataList {
    width: 100%;
    padding: 0 12px;
    box-sizing: border-box;
    max-height: 422px;
    overflow-y: auto;
    li {
      cursor: pointer;
      color: #fff;
      padding: 6px 0;
    }
    .no-search {
        img {
          width: 20px;
          height: 20px;
        }
      }
  }
  /deep/.el-input--small .el-input__inner {
    width: 225px;
    height: 32px;
    line-height: 32px;
  }
  /deep/.el-input__prefix {
    margin-top: 1px;
    font-size: 18px;
  }
  /deep/.el-input__suffix {
    margin: 2px;
  }
}
</style>